
            <!DOCTYPE html>
            <html lang="en">
            <head>
                <meta charset="UTF-8">
                <title>k8s 通过环境变量获取Pod信息</title>
            </head>
            <body>
            <a href="https://andyoung.blog.csdn.net">原作者博客</a>
            <div id="content_views" class="markdown_views prism-atom-one-light">
                    <svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
                        <path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path>
                    </svg>
                    <pre><code>env:
- name: MY_NODE_NAME
    valueFrom:
    fieldRef:
        fieldPath: spec.nodeName                       // 节点名称
- name: MY_POD_NAME
    valueFrom:
    fieldRef:
        fieldPath: metadata.name                        // pod 名称
- name: MY_POD_NAMESPACE
    valueFrom:
    fieldRef:
        fieldPath: metadata.namespace              // 命名空间
- name: MY_POD_IP
    valueFrom:
    fieldRef:
        fieldPath: status.podIP                              // pod ip
- name: MY_POD_SERVICE_ACCOUNT
    valueFrom:
    fieldRef:
        fieldPath: spec.serviceAccountName    // 账号名称
</code></pre> 
<p>官方链接：<a href="https://kubernetes.io/zh/docs/tasks/inject-data-application/environment-variable-expose-pod-information/" rel="nofollow">https://kubernetes.io/zh/docs/tasks/inject-data-application/environment-variable-expose-pod-information/</a></p>
                </div>
            </body>
            </html>
            